#include <stdio.h>

int concate(int i, int j, int pro)
{
	int a[10]={0};
	while (i) {
		a[i%10]++;
		if (a[i%10] != 1 || i%10 == 0)return 0;
		i /=10;
	}
	while (j) {
		a[j%10]++;
		if (a[j%10] != 1 || j%10 == 0)return 0;
		j /=10;
	}
	while (pro) {
		a[pro%10]++;
		if (a[pro%10] != 1 || pro%10 == 0)return 0;
		pro /=10;
	}
	int k;
	for (k=1; k<=9; k++) {
		if (a[k]!=1)return 0;
	}
	return 1;
}
int main()
{
	printf("%d\n", concate(38, 186, 7254));
	int i, j, a[10]={0}, sum=0;
	for (i=2; i<=9; i++) {
		for (j=1234; j<=9876; j++) {
			if (concate(i, j, i*j)) {
				printf("%d %d %d\n", i, j, i*j);
				sum = sum +i*j;
			}
		}
	}
	for (i=12; i<=98; i++) {
		for (j=123; j<=987; j++) {
			if (concate(i, j, i*j)) {
				printf("%d %d %d\n", i, j, i*j);
				sum = sum+i*j;
			}
		}
	}
	printf("\n%d\n", sum);
}
